﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zebra.Utility
{
    public static class DataTypeConversion
    {
        #region Static Public Functions
    
        /// <summary>
        /// Takes the numeric value and returns the day of the week.
        /// </summary>
        /// <param name="DayOfWeek">The int representation of the day of the week</param>
        /// <returns>returns the string value for the day of the week</returns>
        public static string IntToDay(int DayOfWeek)
        {
            switch (DayOfWeek)
            {
                case 1:
                    return "Sunday";
                case 2:
                    return "Monday";
                case 3:
                    return "Tuesday";
                case 4:
                    return "Wednesday";
                case 5:
                    return "Thursday";
                case 6:
                    return "Friday";
                case 7:
                    return "Saturday";
            }
            return "";
        }

        /// <summary>
        /// Takes the day of the week and returns the numeric value (1-7).
        /// </summary>
        /// <param name="DayOfWeek">The string representation of the day of the week</param>
        /// <returns>returns the int value for the day of the week</returns>
        public static int DayToInt(string DayOfWeek)
        {
            switch (DayOfWeek)
            {
                case "Sunday":
                    return 1;
                case "Monday":
                    return 2;
                case "Tuesday":
                    return 3;
                case "Wednesday":
                    return 4;
                case "Thursday":
                    return 5;
                case "Friday":
                    return 6;
                case "Saturday":
                    return 7;
            }
            return 0;
        }

        /// <summary>
        /// Takes the int value for the month and returns the name of the month
        /// </summary>
        /// <param name="Month">The month in int form</param>
        /// <returns>returns the string value for the month</returns>
        public static string IntMonthToString(int Month)
        {
            switch (Month)
            {
                case 1:
                    return "January";
                case 2:
                    return "February";
                case 3:
                    return "March";
                case 4:
                    return "April";
                case 5:
                    return "May";
                case 6:
                    return "June";
                case 7:
                    return "July";
                case 8:
                    return "August";
                case 9:
                    return "September";
                case 10:
                    return "October";
                case 11:
                    return "November";
                case 12:
                    return "December";
                default:
                    return "";
            }
        }

        /// <summary>
        /// Takes the int value for the month and returns the name of the month
        /// </summary>
        /// <param name="Month">The month in int form</param>
        /// <returns>returns the string value for the month</returns>
        public static int StringToIntMonth(string Month)
        {
            switch (Month)
            {
                case "January":
                    return 1;
                case "February":
                    return 2;
                case "March":
                    return 3;
                case "April":
                    return 4;
                case "May":
                    return 5;
                case "June":
                    return 6;
                case "July":
                    return 7;
                case "August":
                    return 8;
                case "September":
                    return 9;
                case "October":
                    return 10;
                case "November":
                    return 11;
                case "December":
                    return 12;
                default:
                    return 0;
            }
        }

        /// <summary>
        /// Converts the given month int to month name
        /// </summary>
        /// <param name="month">month in</param>
        /// <param name="abbrev">return abbreviated or not</param>
        /// <returns>Short or long month name</returns>
        public static string GetMonthName(int month, bool abbrev)
        {
            DateTime date = new DateTime(1900, month, 1);
            if (abbrev) return date.ToString("MMM");
            return date.ToString("MMMM");
        }

        /// <summary>
        /// Convert string format to datetime format.
        /// </summary>
        /// <see http://dotnetperls.com/datetime-format/>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime ConvertStringToDateTime(string date)
        {
            IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-GB", true);
            DateTime theDateTime = DateTime.ParseExact(date, "d-M-yyyy", theCultureInfo);
            return theDateTime;
        }

        #endregion
    }
}
